package org.yourorghere;

import MeshlessShapeFunctions.JCubicSpline;
import MeshlessShapeFunctions.JExponential;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction;
import MeshlessShapeFunctions.Particle;
import com.sun.opengl.util.Animator;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;



/**
 * SimpleJOGL.java <BR>
 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */
public class SimpleJOGL implements GLEventListener,KeyListener {

    public static void main(String[] args) {
        ////////////////////////////////////////////////////////////////////////////////////////
        ArrayList<Particle> ls = new ArrayList<Particle>();
        ls.add(new Particle(0.0, 0.0, 1));
        ls.add(new Particle(0.0, 0.25, 1));
        ls.add(new Particle(0.0, 0.75, 1));
        ls.add(new Particle(0.0, 1.0, 1));

        ls.add(new Particle(0.0, 0.-25, 1));
        ls.add(new Particle(0.0, 0.-75, 1));
        ls.add(new Particle(0.0, -1.0, 1));

        ls.add(new Particle(0.25, 0.0, 1));
        ls.add(new Particle(0.25, 0.25, 1));
        ls.add(new Particle(0.25, 0.75, 1));
        ls.add(new Particle(0.25, 1.0, 1));

        ls.add(new Particle(0.25, -0.25, 1));
        ls.add(new Particle(0.25, -0.75, 1));
        ls.add(new Particle(0.25, -1.0, 1));

        ls.add(new Particle(-0.25, 0.0, 1));
        ls.add(new Particle(-0.25, 0.25, 1));
        ls.add(new Particle(-0.25, 0.75, 1));
        ls.add(new Particle(-0.25, 1.0, 1));

        ls.add(new Particle(-0.25, -0.25, 1));
        ls.add(new Particle(-0.25, -0.75, 1));
        ls.add(new Particle(-0.25, -1.0, 1));

        
        ls.add(new Particle(0.75, 0.0, 1));
        ls.add(new Particle(0.75, 0.25, 1));
        ls.add(new Particle(0.75, 0.75, 1));
        ls.add(new Particle(0.75, 1.0, 1));
        
        ls.add(new Particle(0.75, -0.25, 1));
        ls.add(new Particle(0.75, -0.75, 1));
        ls.add(new Particle(0.75, -1.0, 1));
        
        ls.add(new Particle(-0.75, 0.0, 1));
        ls.add(new Particle(-0.75, 0.25, 1));
        ls.add(new Particle(-0.75, 0.75, 1));
        ls.add(new Particle(-0.75, 1.0, 1));
        
        ls.add(new Particle(-0.75, -0.25, 1));
        ls.add(new Particle(-0.75, -0.75, 1));
        ls.add(new Particle(-0.75, -1.0, 1));

        ls.add(new Particle(1.0, 0.0, 1));
        ls.add(new Particle(1.0, 0.25, 1));
        ls.add(new Particle(1.0, 0.75, 1));
        ls.add(new Particle(1.0, 1.0, 1));
        
        ls.add(new Particle(1.0, -0.25, 1));
        ls.add(new Particle(1.0, -0.75, 1));
        ls.add(new Particle(1.0, -1.0, 1));
        
        ls.add(new Particle(-1.0, 0.0, 1));
        ls.add(new Particle(-1.0, 0.25, 1));
        ls.add(new Particle(-1.0, 0.75, 1));
        ls.add(new Particle(-1.0, 1.0, 1));
        
        ls.add(new Particle(-1.0, -0.25, 1));
        ls.add(new Particle(-1.0, -0.75, 1));
        ls.add(new Particle(-1.0, -1.0, 1));

        SimpleJOGL.jm = new JMeshlessInterpolationFunction(2, 0.5, 0.5, 1.0, new JExponential(0.3,0.5));
        jm.setNodeList(ls);
        ////////////////////////////////////////////////////////////////////////////////////////



        //JFrame frame = new JFrame("Simple JOGL Application");
        //GLCanvas canvas = new GLCanvas();
        //SimpleJOGL jogl = new SimpleJOGL(frame);

        /*if(args.length!=0){
        jogl.path = args[0];
        System.out.println(jogl.path);
        }

        canvas.addGLEventListener(jogl);
        canvas.addKeyListener(jogl);

        frame.add(canvas);
        frame.addKeyListener(jogl);
        frame.setSize(1000, 700);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
        // Run this on another thread than the AWT event queue to
        // make sure the call to Animator.stop() completes before
        // exiting
        new Thread(new Runnable() {

        public void run() {
        animator.stop();
        System.exit(0);

        }
        }).start();
        }
        });
        // Center frame
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();*/
    }



    //GL gl;
    Color	m_BkClr;	// Background color
    JFrame frame;
    public String path = "C:\\Documents and Settings\\mark\\My Documents\\NetBeansProjects\\MySimpleFEM\\New Folder\\";
	/*HGLRC	m_hRC;		// Rendering context OpenGL
    HDC	m_hdc;		// Windows device context*/
	float	m_AngleX;	// Rotation angle (around X-axis)
	float m_AngleY;	// Rotation angle (around Y-axis)
    float m_AngleZ; // Rotation angle (around Z-axis)
	float	m_AngleView;	// Perspective angle
	float	m_fRangeX;	// Graphics dimension (along X-axis)
	float m_fRangeY;	// Graphics dimension (along Y-axis)
	float m_fRangeZ;	// Graphics dimension (along Z-axis)
	float	m_dx;		// Displacement quantum (along X-axis)
	float m_dy;		// Displacement quantum (along Y-axis)
	float	m_xTrans;	// Displacement (along X-axis)
	float m_yTrans;	// Displacement (along Y-axis)
	float m_zTrans;	// Displacement (along Z-axis)
	int m_FillMode;	// Polygon filling mode
	boolean	m_bCaptured;	// Mouse capture flag
	boolean	m_bRightButton;	// Right mouse button flag
	boolean	m_bQuad;	// Flag of using GL_QUAD (instead of GL_QUAD_STRIP)
	Point	m_pt;		// Current mouse position
	int	m_xSize;	// Current client window sixe (along X-axis)
	int	m_zSize;	// Current client window sixe (along -axis)
	//ArrayList<CPoint3D> m_cPoints;	// Graphics dimension (along X-axis)
	int[]	m_LightParam = new int[11];	// Graphics dimension (along X-axis)
	//CPropDlg *m_pDlg;		// Graphics dimension (along X-axis)

    public SimpleJOGL(JFrame frame) {
        try {
            this.frame = frame;
            //====== Initial image turn
            m_AngleX = 0.f;
            m_AngleY = 0.f;
            m_AngleZ = 0.f;
            //====== Projection matrix view angle
            m_AngleView = 45.f;
            //====== Initial bkcolor
            m_BkClr = new Color(255, 255, 255);
            // Initial mode to fill the inner polygons (quads) points
            m_FillMode = GL.GL_FILL;
            //====== Initial plot creation
            //DefaultGraphic();
            //====== Initial image shift
            //====== One and a half object size (backward)
            m_zTrans = -1.5f * m_fRangeX;
            m_xTrans = m_yTrans = 0.f;
            //== Initial shift quantums (for rotation animation)
            m_dx = m_dy = 0.f;
            //====== Mouse is not captured
            m_bCaptured = false;
            //====== Right mouse button has not been pressed
            m_bRightButton = false;
            //====== We use quads to create the surface
            m_bQuad = true;
            //====== Initial lighting params
            m_LightParam[0] = 50; // X position
            m_LightParam[1] = 80; // Y position
            m_LightParam[2] = 100; // Z position
            m_LightParam[3] = 15; // Ambient light
            m_LightParam[4] = 70; // Diffuse light
            m_LightParam[5] = 100; // Specular light
            m_LightParam[6] = 100; // Ambient material
            m_LightParam[7] = 100; // Diffuse material
            m_LightParam[8] = 40; // Specular material
            m_LightParam[9] = 70; // Shininess material
            m_LightParam[10] = 0; // Emission material
            getNodes(path+"\\file.1.node");
            getTriangles(path+"\\file.1.ele");
            getSolvedResults(path+"\\file.txt");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(SimpleJOGL.class.getName()).log(Level.SEVERE, null, ex);
        }
//        NewDialogShkala sh = new NewDialogShkala(null, false, min, max);
//        sh.setVisible(true);

    }



    public void init(GLAutoDrawable drawable) {
            // Use debug pipeline
            // drawable.setGL(new DebugGL(drawable.getGL()));

            GL gl = drawable.getGL();
            System.err.println("INIT GL IS: " + gl.getClass().getName());
            // Enable VSync
            //gl.glShadeModel(GL.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT,
        GL.GL_NICEST);
            gl.setSwapInterval(1);
            // Setup the drawing area and shading mode
            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            //gl.glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
            gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.

    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL gl = drawable.getGL();
        GLU glu = new GLU();

        if (height <= 0) { // avoid a divide by zero error!

            height = 1;
        }
        //gl.glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
        final float h = (float) width / (float) height;
        /*gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(-1.5, 1.5, -1.5, 1.5, -2.0, 4.0);
        glu.gluPerspective(50.0f, h, 1.0, 1000.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();*/
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(50.0f, h, 1.0, 1000.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();

    }
//private float rotateT = 70.0f;
    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        // Clear the drawing area
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        gl.glEnable(GL.GL_DEPTH_TEST);
        // Reset the current matrix to the "identity"
        gl.glLoadIdentity();

        gl.glEnable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_LIGHT0);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_COLOR_MATERIAL);
        SetBkColor(gl);//????
        SetLight(gl);





        gl.glTranslatef(m_xTrans, m_yTrans, m_zTrans);
        
        gl.glRotatef(m_AngleX, 1.0f, 0.0f, 0.0f);
        gl.glRotatef(m_AngleY, 0.0f, 1.0f, 0.0f);
        gl.glRotatef(m_AngleZ, 0.0f, 0.0f, 1.0f);
        //gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);



        gl.glColor3d(1.0, 0.0, 0.0);

        if(TrList!=null){
            
            for (int i = 0; i < TrList.size(); i++) {
                Triangle triangle = TrList.get(i);
                gl.glBegin(gl.GL_TRIANGLES);

                double color = (max-Results.get(triangle.A-1))/(max-min);

                if(Results.get(triangle.A-1)>(max+min)/3.0*2){
                    gl.glColor3d(color, 0.0,0.0);
                }else{
                    if(Math.abs(Results.get(triangle.A-1))<(max+min)/3.0){
                        gl.glColor3d(0.0, 0.0,color);
                    }else{
                        if(Math.abs(Results.get(triangle.A-1))<(max+min)/12.0*5.0){
                            gl.glColor3d(0.0, 0.3,color);
                        }else{
                            if(Math.abs(Results.get(triangle.A-1))<(max+min)/2.0){
                                gl.glColor3d(0.1, 0.3,color);
                            }else{
                                if(Math.abs(Results.get(triangle.A-1))<(max+min)/12.0*7.0){
                                    gl.glColor3d(color, 0.3,0.1);
                                }else{
                                    gl.glColor3d(color, 0.3,0.0);
                                }
                            }

                        }

                        gl.glColor3d(0.0, color,0.0);
                    }
                }
                    gl.glVertex3d(NodeList.get(triangle.A-1).x,NodeList.get(triangle.A-1).y,-color );

                color = (max-Results.get(triangle.B-1))/(max-min);
                if(Results.get(triangle.B-1)>(max+min)/3.0*2){
                    gl.glColor3d(color, 0.0,0.0);
                }else{
                    if(Math.abs(Results.get(triangle.B-1))<(max+min)/3.0){
                        gl.glColor3d(0.0, 0.0,color);
                    }else{
                        if(Math.abs(Results.get(triangle.B-1))<(max+min)/12.0*5.0){
                            gl.glColor3d(0.0, 0.3,color);
                        }else{
                            if(Math.abs(Results.get(triangle.B-1))<(max+min)/2.0){
                                gl.glColor3d(0.1, 0.3,color);
                            }else{
                                if(Math.abs(Results.get(triangle.B-1))<(max+min)/12.0*7.0){
                                    gl.glColor3d(color, 0.3,0.1);
                                }else{
                                    gl.glColor3d(color, 0.3,0.0);
                                }
                            }

                        }

                        gl.glColor3d(0.0, color,0.0);
                    }
                }
                    gl.glVertex3d(NodeList.get(triangle.B-1).x,NodeList.get(triangle.B-1).y,-color );

                color = (max-Results.get(triangle.C-1))/(max-min);
                if(Results.get(triangle.C-1)>(max+min)/3.0*2){
                    gl.glColor3d(color, 0.0,0.0);
                }else{
                    if(Math.abs(Results.get(triangle.C-1))<(max+min)/3.0){
                        gl.glColor3d(0.0, 0.0,color);
                    }else{
                        if(Math.abs(Results.get(triangle.C-1))<(max+min)/12.0*5.0){
                            gl.glColor3d(0.0, 0.3,color);
                        }else{
                            if(Math.abs(Results.get(triangle.C-1))<(max+min)/2.0){
                                gl.glColor3d(0.1, 0.3,color);
                            }else{
                                if(Math.abs(Results.get(triangle.C-1))<(max+min)/12.0*7.0){
                                    gl.glColor3d(color, 0.3,0.1);
                                }else{
                                    gl.glColor3d(color, 0.3,0.0);
                                }
                            }

                        }

                        gl.glColor3d(0.0, color,0.0);
                    }
                }
                    gl.glVertex3d(NodeList.get(triangle.C-1).x,NodeList.get(triangle.C-1).y,-color );
                    /*gl.glColor3f(1.0f, 1.f, 1.f);
                gl.glVertex3d(NodeList.get(triangle.A-1).x,NodeList.get(triangle.A-1).y,Results.get(triangle.A-1) );
                gl.glVertex3d(NodeList.get(triangle.B-1).x,NodeList.get(triangle.B-1).y,Results.get(triangle.B-1) );
                gl.glVertex3d(NodeList.get(triangle.C-1).x,NodeList.get(triangle.C-1).y,Results.get(triangle.C-1) );*/
                gl.glEnd();
            }
        }

        // Flush all drawing operations to the graphics card
        //System.out.println(NodeList.size());
        gl.glFlush();
    }

    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }



    private void SetLight(GL gl) {
        //====== Both surface sides are considered when calculating
        //====== each pixel color with the lighting formula

        gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE,1);

        //====== Light source position depends on the object sizes scaled to (0,100)

        float fPos[] =new float[]
        {
    		(m_LightParam[0]-50)*m_fRangeX/100,
        	(m_LightParam[1]-50)*m_fRangeY/100,
            (m_LightParam[2]-50)*m_fRangeZ/100,
    		1.f
    	};

        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, FloatBuffer.wrap(fPos));

    	//====== Ambient light intensity
    	float f = m_LightParam[3]/100.f;
    	float[] fAmbient = new float[]{ f, f, f, 0.f };
    	gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, FloatBuffer.wrap(fAmbient));

        //====== Diffuse light intensity
        f = m_LightParam[4]/100.f;
        float[] fDiffuse = new float[]{ f, f, f, 0.f };
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, FloatBuffer.wrap(fDiffuse));

        //====== Specular light intensity
        f = m_LightParam[5]/100.f;
        float[] fSpecular = new float[]{ f, f, f, 0.f };
    	gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, FloatBuffer.wrap(fSpecular));

        //====== Surface material reflection properties for each light component
        f = m_LightParam[6]/100.f;
        float[] fAmbMat = new float[]{ f, f, f, 0.f };
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, FloatBuffer.wrap(fAmbMat));

        f = m_LightParam[7]/100.f;
        float[] fDifMat = new float[]{ f, f, f, 1.f };
    	gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, FloatBuffer.wrap(fDifMat));

    	f = m_LightParam[8]/100.f;
    	float[] fSpecMat = new float[]{ f, f, f, 0.f };
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, FloatBuffer.wrap(fSpecMat));

    	//====== Material shininess
    	float fShine = 128 * m_LightParam[9]/100.f;
        gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, fShine);

    	//====== Material light emission property
    	f = m_LightParam[10]/100.f;
        float[] fEmission = new float[]{ f, f, f, 0.f };
        gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, FloatBuffer.wrap(fEmission));
    }

private void SetBkColor(GL gl)
{
	//====== Split the color to 3 components
	float red	= m_BkClr.getRed()/255.f,
			 green	= m_BkClr.getGreen()/255.f,
			 blue	= m_BkClr.getBlue()/255.f;
	//====== Set the clear (background) color
	gl.glClearColor (red, green, blue, 0.f);

	//====== Actual background erasure
	gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}




    //////////////////////////////////////////////////////
    public static ArrayList<Double> Results;
    public static ArrayList<Node> NodeList;
    public static ArrayList<Triangle> TrList;
    public static JMeshlessInterpolationFunction jm;
    public static double max;
    public static double min;

    public static double maxx;
    public static double minx;
    public static double maxy;
    public static double miny;



    public static void getNodes(String FilePath) throws FileNotFoundException{
        Scanner in = new Scanner((new FileInputStream(FilePath)));
            NodeList  = new ArrayList<Node>();
            int n = in.nextInt();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            for (int i = 0; i <n; i++) {
                in.next();
                NodeList.add(new Node( ( Double.parseDouble(in.next()) ), ( Double.parseDouble(in.next()) ) , ( isTrue(Integer.parseInt(in.next())) )  ));
            }


    }
    private static boolean isTrue(int s){
        if(s==0){return false;}else{return true;}
    }

    public static void getTriangles(String FilePath) throws FileNotFoundException{
            Scanner in = new Scanner((new FileInputStream(FilePath)));
            TrList  = new ArrayList<Triangle>();
            int n = in.nextInt();
            in.nextInt();
            in.nextInt();
            for (int i = 0; i <n; i++) {
                in.next();
                TrList.add(new Triangle( ( Integer.parseInt(in.next()) ), ( Integer.parseInt(in.next()) ) , ( Integer.parseInt(in.next()) )  ));
            }
    }

    public static void getSolvedResults(String FilePath) throws FileNotFoundException{
        Results = new ArrayList<Double>();
        for (int i = 0; i < NodeList.size(); i++) {
            Node node = NodeList.get(i);
            Results.add(jm.calculate(node.x, node.y));
            System.out.println(Results.get(Results.size()-1));
        }

    }

    public void keyTyped(KeyEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
        //this.frame.repaint();
        //this.

    }

    public void keyPressed(KeyEvent e) {
        float param = 0.25f;
        if((e.getKeyCode()==KeyEvent.VK_UP)&&(!e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_zTrans-=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_DOWN)&&(!e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_zTrans+=param;
        }
        if((e.getKeyCode()==KeyEvent.VK_UP)&&(e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_yTrans+=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_DOWN)&&(e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_yTrans-=param;
        }
        if((e.getKeyCode()==KeyEvent.VK_LEFT)&&(e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_xTrans-=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_RIGHT)&&(e.isControlDown())&&(!e.isShiftDown())&&(!e.isAltDown())){
            m_xTrans+=param;
        }

        if((e.getKeyCode()==KeyEvent.VK_LEFT)&&(e.isAltDown())&&(!e.isControlDown())&&(!e.isShiftDown())){
            m_AngleY-=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_RIGHT)&&(e.isAltDown())&&(!e.isControlDown())&&(!e.isShiftDown())){
            m_AngleY+=param;
        }
        if((e.getKeyCode()==KeyEvent.VK_UP)&&(e.isAltDown())&&(!e.isControlDown())){
            m_AngleX-=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_DOWN)&&(e.isAltDown())&&(!e.isControlDown())){
            m_AngleX+=param;
        }

        if((e.getKeyCode()==KeyEvent.VK_UP)&&(e.isShiftDown())){
            m_AngleZ-=param;
            //System.out.println(m_zTrans);
        }
        if((e.getKeyCode()==KeyEvent.VK_DOWN)&&(e.isShiftDown())){
            m_AngleZ+=param;
        }

        if(e.getKeyCode()==KeyEvent.VK_ESCAPE){
            this.frame.setVisible(false);
        }


        //System.out.println(m_zTrans);
        //throw new UnsupportedOperationException("Not supported yet.");
        //System.out.println("keyPressed");
    }

    public void keyReleased(KeyEvent e) {
        System.out.println("keyReleased");
    }

}

